using UnityEditor;
using UnityEngine;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

public class ParseDiretionLight : ParseObjectHandle<Light>
{
    public override void Prase(ExportSetting ExportSetting, Light obj, JArray jArray)
    {
        var staticSetting = ExportSetting.CocosObjectConfig["cc.StaticLightSettings"].DeepClone();

        JToken ccLight = null;
        switch (obj.type)
        {
            case LightType.Directional:
                ccLight = ExportSetting.CocosObjectConfig["cc.DirectionalLight"].DeepClone();
                ccLight["_color"] = AssetHelper.TransforCCObject(obj.color);
                ccLight["_illuminance"] = obj.intensity * 65000;
                ccLight["_colorTemperature"] = obj.bounceIntensity * 6550;
                break;
            case LightType.Spot:
                ccLight = ExportSetting.CocosObjectConfig["cc.SpotLight"].DeepClone();
                ccLight["_color"] = AssetHelper.TransforCCObject(obj.color);
                ccLight["_range"] = obj.range;
                ccLight["_spotAngle"] = obj.spotAngle;
                ccLight["_illuminance"] = obj.intensity * 1913.8445799108247;
                ccLight["_colorTemperature"] = obj.bounceIntensity * 6550;
                break;
            case LightType.Point:
                ccLight = ExportSetting.CocosObjectConfig["cc.SpotLight"].DeepClone();
                ccLight["_color"] = AssetHelper.TransforCCObject(obj.color);
                ccLight["_range"] = obj.range;
                ccLight["_illuminance"] = obj.intensity * 1913.8445799108247;
                ccLight["_colorTemperature"] = obj.bounceIntensity * 6550;
                break;
        }
        if (obj.bounceIntensity != 1)
        {
            ccLight["_useColorTemperature"] = true;
        }
        jArray.Add(ccLight);
        ccLight = jArray[jArray.Count - 1];
        if (obj.lightmapBakeType == LightmapBakeType.Baked)
        {
            staticSetting["_baked"] = true;
        }
        if (obj.shadows == LightShadows.None)
        {
            staticSetting["_castShadow"] = false;
        }
        else
        {
            staticSetting["_castShadow"] = true;
        }
        ccLight["_staticSettings"] = AssetHelper.CreateIdJObject(jArray.Count);
        jArray.Add(staticSetting);
    }
}
